import 'dart:ffi';

class MSCategory {
  int? id;
  String userId;
  String name;
  String time;
  List<MSItem> items;

  MSCategory(
      {required this.name,
      required this.userId,
      this.id,
      required this.time,
      required this.items});
  factory MSCategory.fromJson(Map<String, dynamic> map) {
    return MSCategory(
        name: map["name"],
        userId: map["userId"],
        time: map["time"],
        items: [],
        id: map["id"]);
  }
  get amountOfFinished =>
      items.where((element) => element.isFinished == 1).length;
  get amountOfPending =>
      items.where((element) => element.isFinished == 0).length;

  List<MSItem> get listOfFinished => items.where((element) => element.isFinished == 1).toList();
  List<MSItem> get listOfPending => items.where((element) => element.isFinished == 0).toList();
}



class MSItem {
  int? id;
  int categoryId;
  String name;
  String time;
  int isFinished;
  String userId;
  MSItem(
      {required this.time,
      this.id,
      required this.name,
      required this.categoryId,
      required this.isFinished,
      required this.userId});
  factory MSItem.fromJson(Map<String, dynamic> map) {
    return MSItem(
        name: map["name"],
        categoryId: map["categoryId"],
        time: map["time"],
        id: map["id"],
        isFinished: map["isFinished"],
        userId: map["userId"]
    );
  }
}
